﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_UpTradeGoods_detail : System.Web.UI.Page
{
    string projectid, strSql, SupplyGoodsId;
    int GoodsId;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        SupplyGoodsId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["SupplyGoodsId"]));
        projectid = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        //int project = Convert.ToInt32(Request.QueryString["projectid"]);
        //if (project == 8)
        //{
        //    this.Label1.Text = "中标价格(最小包装)";
        //    this.Label2.Visible = false;
        //}
        //if (project == 9)
        //{
        //    this.Label1.Text = "最高零售价(最小包装)";
        //    this.Label2.Visible = false;
        //}
        //if (project == 10)
        //{
        //    this.Label1.Text = "最高限价(最小包装)";
        //    System.Text.StringBuilder stringbulide = new System.Text.StringBuilder();
        //    stringbulide.Append("<tr><td  class=\"table_td3\" style=\"width: 160px\">");
        //    stringbulide.Append("最高零售价(最小包装)</td><td class=\"table_td2\" colspan=\"3\">");
        //    stringbulide.Append("<input name=\"startprice\" id=\"startprice\" type=\"Text\" style=\"width:231px;\" /><span></span>");
        //    stringbulide.Append("</td></tr>");
        //    stringbulide.Append("<tr><td class=\"table_td3\" style=\"width: 160px\">待调价格（最小包装）：</td><td class=\"table_td2\" colspan=\"3\">");
        //    stringbulide.Append("<input name=\"endprice\"  id=\"endprice\" type=\"Text\" style=\"width:231px;\" /><span></span>");
        //    stringbulide.Append("<input id=\"save2\" name=\"save2\"  type=\"Button\" class=\"button_bg6\"  style=\"width:64px;\" runat=\"server\"  value=\"保 存\" />");
        //    stringbulide.Append("&nbsp; &nbsp; &nbsp; <input name=\"history2\" id=\"history2\" type=\"Button\" class=\"button_bg6\" style=\"width:94px;\" value=\"查看历史记录\" runat=\"Server\"/></td></tr>");
        //    this.Label2.Text = stringbulide.ToString();


        //}
        //if (project == 12)
        //{
        //    this.Label1.Text = "最高零售价(最小包装)";
        //    this.Label2.Visible = false;
        //}
        //if (project == 11)
        //{
        //    this.label3.Visible = false;
        //}
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
          
            if (!IsPostBack)
            {


                int project = Convert.ToInt32(SysFun.IsSQL(Request.QueryString["projectid"]));
                if (project == 8)
                {
                    this.Label1.Text = "中标价格(最小包装)";
                    this.Label2.Visible = false;
                    this.label4.Visible = false;
                }
                if (project == 9)
                {
                    this.Label1.Text = "最高零售价(最小包装)";
                    this.Label2.Visible = false;
                    this.label4.Visible = false;
                }
                //if (project == 10)
                //{
                //    this.Label1.Text = "最高限价(最小包装)";
                //    System.Text.StringBuilder stringbulide = new System.Text.StringBuilder();
                //    stringbulide.Append("<tr><td  class=\"table_td3\" style=\"width: 160px\">");
                //    stringbulide.Append("最高零售价(最小包装)</td><td class=\"table_td2\" colspan=\"3\">");
                //    stringbulide.Append("<input name=\"startprice\" id=\"startprice\" type=\"Text\" style=\"width:231px;\" /><span></span>");
                //    stringbulide.Append("</td></tr>");
                //    stringbulide.Append("<tr><td class=\"table_td3\" style=\"width: 160px\">待调价格（最小包装）：</td><td class=\"table_td2\" colspan=\"3\">");
                //    stringbulide.Append("<input name=\"endprice\"  id=\"endprice\" type=\"Text\" style=\"width:231px;\" /><span></span>");
                //    stringbulide.Append("<input id=\"save2\" name=\"save2\"  type=\"Button\" class=\"button_bg6\"  style=\"width:64px;\" runat=\"server\"  value=\"保 存\" />");
                //    stringbulide.Append("&nbsp; &nbsp; &nbsp; <input name=\"history2\" id=\"history2\" type=\"Button\" class=\"button_bg6\" style=\"width:94px;\" value=\"查看历史记录\" runat=\"Server\"/></td></tr>");
                //    this.Label2.Text = stringbulide.ToString();


                //}


                if (project == 10)
                {
                    this.Label1.Text = "最高限价(最小包装)";
                    this.label4.Visible = true;
                    this.Label5.Text = "最高零售价(最小包装)";
                }
                if (project == 12)
                {
                    this.Label1.Text = "最高零售价(最小包装)";
                    this.Label2.Visible = false;
                    this.label4.Visible = false;
                }
                if (project == 11)
                {
                    this.label3.Visible = false;
                    this.label4.Visible = false;
                }
              
              
                Db db = new Db();
                System.Data.IDataReader dr;
                strSql = "select * from SupplyPlan_Goods where SupplyGoodsId=" + SupplyGoodsId;
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    
                    labProductName.Text = dr["productname"].ToString();
                    labOutlookc.Text = dr["outlookc"].ToString();
                    labMedicinemodel.Text = dr["medicinemodel"].ToString();
                    labProductCode.Text = dr["ProductCode"].ToString();
                    labBidTableName.Text = dr["BidTableName"].ToString();
                    LabBidTableType.Text = dr["BidTableType"].ToString();
                    LabGoodsId.Text = SysFun.ToInt(dr["GoodsId"]).ToString();
                    LabGoodsName.Text = dr["goodsname"].ToString();
                    LabBidTableOutlookc.Text = dr["BidTableOutlookc"].ToString();
                    LabFactor.Text = dr["Factor"].ToString();
                    LabPack.Text = dr["Pack"].ToString();
                    LabCompanyName_SC.Text = dr["CompanyName_SC"].ToString();
                    txtCompanyName_PS.Text = dr["CompanyName_PS"].ToString();
                   // HiddenField1.Value = dr["AccountId_PS"].ToString();
                   // txtLicence.Text = dr["Licence"].ToString();
                    //txtLicenceDate.Text = dr["LicenceDate"].ToString();
                    LabCompanyName_TB.Text = dr["CompanyName_TB"].ToString();
                    rdoQualityLevels.SelectedValue = SysFun.ToTrim(dr["QualityLevels"]);
                    rdoGoodsState.SelectedValue = SysFun.ToTrim(dr["GoodsState"]);
                    rdoIsUse.SelectedValue = SysFun.ToTrim(dr["IsUse"]);
                    if (SysFun.ToTrim(dr["IsUse"])== "0")
                    {
                        Panel1.Visible = true;
                        TextArea1.Value = SysFun.ToTrim(dr["NopassExplain"]);
                    }
                    else
                    {
                        Panel1.Visible = false;
                    }
                    BidPrice.Text = SysFun.OutNum(dr["BidPrice"],2);
                    this.TextBox1.Text = SysFun.OutNum(dr["RetailPrice"], 2);
                    waitPrice.Text = SysFun.OutNum(dr["LatestPrice"], 2);
                    this.TextBox2.Text = SysFun.OutNum(dr["MEMO4"], 2);
                    TextArea1.Value = SysFun.ToTrim(dr["NopassExplain"]);
                   
                }
                dr.Close();
                dr.Dispose();
                db.Close();
            }
        }     
    }

    protected void Btnpass_Click(object sender, EventArgs e)
    {
        Db db = new Db();
        strSql = "update SupplyPlan_Goods set IsUse='1'  where SupplyGoodsId=" + SupplyGoodsId;
        strSql += "  update HospitalPurchase set state=1 where SupplyGoodsId=" + SupplyGoodsId; //修改为中介撤废 state 0 医院撤废 1 为正常采购 2 为中介撤废
        db.Command(strSql);
       
        
        db.Close();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_Goods,HospitalPurchase", strSql, "../Agency/UpTradeGoods_detail.aspx");
   
        
        Response.Write("<script>alert('该挂网药品恢复成功！！！');window.opener.location.reload();window.close();</script>");
    }
    protected void Btnnopass_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.location.href='checknopass.aspx?SupplyGoodsId=" + SupplyGoodsId +"';</script>");
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        Db db = new Db();       
        System.Data.IDataReader dr;
        strSql = "select * from SupplyPlan_Goods where SupplyGoodsId=" + SupplyGoodsId;
        dr = db.DataReader(strSql);
        while (dr.Read())
        {
            
            GoodsId = SysFun.ToInt(dr["GoodsId"]);            
        }
        dr.Close();
        dr.Dispose();        
       // strSql = "update SupplyPlan_Goods set QualityLevels='" + SysFun.ToTrim(rdoQualityLevels.SelectedValue) + "',CompanyName_PS='" + SysFun.ToTrim(txtCompanyName_PS.Text) + "',AccountId_PS=" + SysFun.ToInt(HiddenField1.Value) + "  where SupplyGoodsId=" + SupplyGoodsId;
        strSql = "update SupplyPlan_Goods set QualityLevels='" + SysFun.ToTrim(rdoQualityLevels.SelectedValue) + "'  where SupplyGoodsId=" + SupplyGoodsId;
        db.Command(strSql);
      

        strSql = "update Goods  set QualityLevels='" + SysFun.ToTrim(rdoQualityLevels.SelectedValue) + "' where GoodsId=" + SysFun.ToInt(GoodsId);
        db.Command(strSql);
        
        db.Close();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_Goods,Goods", strSql, "../Agency/UpTradeGoods_detail.aspx");
   
        Response.Write("<script>alert('信息修改成功！！！');window.location='TraTradeDataList.aspx?ProjectId=" + projectid + "' ;</script>");

    }
    protected void savewait_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(Request.QueryString["projectid"]) != 9)
        {
            string strwaitprict;
            strwaitprict = SysFun.ToTrim(waitPrice.Text);
            if (!SysFun.IsNumeric(strwaitprict))
            {
                Response.Write("<script>alert('对不起，价格应该填数字！');window.location='UpTradeGoods_detail.aspx?SupplyGoodsId=" + SupplyGoodsId + "&ProjectId=" + projectid + "' ;</script>");

            }
            else
            {
                Db db = new Db();
                string str = "update SupplyPlan_Goods set LatestPrice=" + strwaitprict + ",waitState =1 where SupplyGoodsId=" + SupplyGoodsId;
                db.Command(str);
                db.Close();
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_Goods,Goods", str, "../Agency/UpTradeGoods_detail.aspx");

                Response.Write("<script>alert('待调价格提交成功！！！');window.location='UpTradeGoods_detail.aspx?SupplyGoodsId=" + SupplyGoodsId + "&ProjectId=" + projectid + "' ;</script>");
            }
        }
        else
        {

            string strwaitprict,Goodsid;
            strwaitprict = SysFun.ToTrim(waitPrice.Text);
            Goodsid = SysFun.ToTrim(this.LabGoodsId.Text);
            if (!SysFun.IsNumeric(strwaitprict))
            {
                Response.Write("<script>alert('对不起，价格应该填数字！');window.location='UpTradeGoods_detail.aspx?SupplyGoodsId=" + SupplyGoodsId + "&ProjectId=" + projectid + "' ;</script>");

            }
            else
            {
                Db db = new Db();
                string str = "update SupplyPlan_Goods set LatestPrice=" + strwaitprict + ",waitState =1 where Goodsid=" + Goodsid;
                db.Command(str);
                db.Close();
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_Goods,Goods", str, "../Agency/UpTradeGoods_detail.aspx");

                Response.Write("<script>alert('待调价格提交成功！！！');window.location='UpTradeGoods_detail.aspx?SupplyGoodsId=" + SupplyGoodsId + "&ProjectId=" + projectid + "' ;</script>");
            }
        }
        
    }
    protected void saveRetail_savewait_Click(object sender, EventArgs e)
    {
        string strwaitprict;
        strwaitprict = SysFun.ToTrim(this.TextBox2.Text);
        if (!SysFun.IsNumeric(strwaitprict))
        {
            Response.Write("<script>alert('对不起，价格应该填数字！');window.location='UpTradeGoods_detail.aspx?SupplyGoodsId=" + SupplyGoodsId + "&ProjectId=" + projectid + "' ;</script>");

        }
        else
        {
            Db db = new Db();
            string str = "update SupplyPlan_Goods set MEMO4=" + strwaitprict + ",waitState1 =1 where SupplyGoodsId=" + SupplyGoodsId;
            db.Command(str);
            db.Close();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_Goods,Goods", str, "../Agency/UpTradeGoods_detail.aspx");

            Response.Write("<script>alert('待调价格提交成功！！！');window.location='UpTradeGoods_detail.aspx?SupplyGoodsId=" + SupplyGoodsId + "&ProjectId=" + projectid + "' ;</script>");
        }

    }
    protected void lookhistory_Click(object sender, EventArgs e) //查看历史
    {
        Response.Write("<script>window.open('Tra_lookhistory.aspx?SupplyGoodsId=" + SupplyGoodsId + "' );</script>");
    }
     protected void history_Click(object sender, EventArgs e) //查看历史
    {
        Response.Write("<script>window.open('lookhistory.aspx?SupplyGoodsId=" + SupplyGoodsId + "' );</script>");
    }
    
}
